package com.example.lzy.listviewsample.AdapterViewFilpper;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

/**
 * Created by lzy on 2018/4/10.
 */

public class MyFilpperAdapter extends BaseAdapter {

    private Context mContext = null;
    private int[] mImageIds = null;

    public MyFilpperAdapter(Context mContext, int[] mImageIds) {
        this.mContext = mContext;
        this.mImageIds = mImageIds;
    }

    @Override
    public int getCount() {
        return mImageIds.length;
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ImageView imageView = null;
        if (null == view){
            imageView =new ImageView(mContext);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));
            view = imageView;
        }else {
            imageView = (ImageView) view;
        }
        imageView.setImageResource(mImageIds[i]);

        return imageView;
    }
}
